﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication
{
    class Delegate
    {
        public delegate int processDelegate(int[] iArray, out int index);

        static int index;

        public static void printMaxValue()
        {
            //      Create a new int[] array.
            int[] iArray = { 3, 5, 2, 6, 8, 1, 9, 0, 7 };

            //  Use the Method - getMaximum.
            Debug.WriteLine("---------The Method - getMaximum starting.");
            int maxValue = Common.getMaximum(iArray, out index);
            Debug.WriteLine("---------The Method - getMaximum Ending.");
            Console.WriteLine("The maximum of the iArray is {0}, and its index is {1}. -------calculated with Method - getMaximum.", maxValue, index + 1);
            Console.ReadKey();

            processDelegate process;        //      Define a delegate variable.
            process = new processDelegate(Common.getMaximum);      //      Initialize the delegate variable.
            //process = getMaximum;     //      Do it with the defferent way(simple way) to initialize the delegate variable.

            //  Use the processDelegate - process. 
            //  NOTE: compare it with the Method - getMaximum above.
            Debug.WriteLine("---------The processDelegate - process starting.");
            maxValue = process(iArray, out index);
            Debug.WriteLine("---------The processDelegate - process Ending.");
            Console.WriteLine("The maximum of the iArray is {0}, and its index is {1}. -------calculated with processDelegate - process.", maxValue, index + 1);
            Console.ReadKey();
        }

    
    }
}
